package com.example.customer.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.concurrent.atomic.AtomicInteger;

@Service
public class TestServiceImple implements ITestService{
    @Autowired
    private RestTemplate restTemplate;

    //保证原子性，相当于加锁访问时不被打扰
    private AtomicInteger s = new AtomicInteger();

    public static String SERVIER_NAME = "provider";


    @Override
    public String test() {
        s.incrementAndGet();
        System.out.println("customer service.....");

        //调用注册中心的服务  第一个参数就是url地址
        String forObject = restTemplate.getForObject("http://" + SERVIER_NAME + "/user/findById", String.class);
        //SERVIER_NAME是单机调用的名字（唯一的）

        return forObject;
    }
}
